package com.zyx.camunda.helpers.behavior;

import com.zyx.camunda.common.utils.CamundaUtils;
import org.camunda.bpm.engine.impl.bpmn.behavior.SequentialMultiInstanceActivityBehavior;
import org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution;

import java.util.Arrays;
import java.util.List;

/**
 * @author zyx
 * @since 2023/9/21 17:06
 */
public class CustomSequentialMultiInstanceActivityBehavior extends SequentialMultiInstanceActivityBehavior {

    @Override
    protected int resolveNrOfInstances(ActivityExecution execution) {
        // collectionExpression 和 collectionVariable 是互斥的
        super.collectionExpression = null;
        // 这里可以自定义获取 审批人列表的 逻辑
        List<String> list = Arrays.asList("300", "301", "302");
        execution.setVariable(super.collectionVariable, list);
        return super.resolveNrOfInstances(execution);
    }

    // @Override
    // protected void evaluateCollectionVariable(ActivityExecution execution, int loopCounter) {
    //     // 这里可以改写获取 assignee 的逻辑
    //     if (usesCollection() && collectionElementVariable != null) {
    //         Object value = CamundaUtils.getElementObject(execution, loopCounter, collectionExpression, collectionVariable);
    //         value = value + "111";
    //         setLoopVariable(execution, collectionElementVariable, value);
    //     }
    // }

}
